<!DOCTYPE html>
<html>
<head>
	<title>03-observer</title>
	<script type="text/javascript" src="js/mummy.js" charset="utf-8"></script>
	
</head>

<body>

<script type="text/javascript" charset="utf-8">

/*reprise exemple de http://www.design-patterns.fr/Decorateur-en-Java-vente-de.html*/

Class($abstract,{
	$define:function Dessert(){
		this.Libelle;
		this.Prix;
		
		this.getLibelle = function(){
			return this.Libelle;
		};
		this.getPrix = function(){
			return this.Prix;
		};		
		
		this.display = function(){
			console.log(this.getLibelle()+' : '+this.getPrix()+' Euros');
		}
	}
		
});

Class({
	$extends:Dessert,
	$define:function Gauffre(){
		
		this.Gauffre = function(){
			this.Libelle = "Gauffre";
			this.Prix = 1.80;
		}
	}
});

Class({
	$extends:Dessert,
	$define:function Crepe(){
		
		this.Crepe = function(){
			this.Libelle = "Crêpe";
			this.Prix = 1.50;
		}
	}
});

Interface(
	function IDecorateurIngredient(){
		this.getLibelle = function(){};
		this.getPrix = function(){};
	}
	
);

Class($abstract,{
	$extends:Dessert,
	$define:function DecorateurIngredient(){
		this.Dessert;
	}	
});

Class({
	$implements:[IDecorateurIngredient],
	$extends:DecorateurIngredient,
	$define:function Chantilly(){
		
		this.Chantilly=function(d){
			this.Dessert = d;
		};
		
		this.getLibelle = function(){
			return this.Dessert.getLibelle()+", chantilly";
		};
		this.getPrix = function(){
			return this.Dessert.getPrix()+0.5;
		};
		
	}
})

Class({
	$implements:[IDecorateurIngredient],
	$extends:DecorateurIngredient,
	$define:function Chocolat(){
		
		this.Chocolat=function(d){
			this.Dessert = d;
		};
		
		this.getLibelle = function(){
			return this.Dessert.getLibelle()+", chocolat";
		};
		this.getPrix = function(){
			return this.Dessert.getPrix()+0.2;
		};
		
	}
})

var d1 = $(Gauffre).getNew(); d1.display();
var d1 = $(Chocolat).getNew(d1); d1.display();

var d2 = $(Crepe).getNew(); d2.display();
d2 = $(Chocolat).getNew(d2); d2.display();
d2 = $(Chantilly).getNew(d2); d2.display();

</script>
	
	

</body>
</html>
